#ifndef AUTOROTATESCREEN_H
#define AUTOROTATESCREEN_H

/*!
 *@brief 根据重力传感器设置屏幕的方向
 * .pro Qt += sensor
 */

#include <QObject>
#include <QMutex>
#include <QOrientationSensor>
#include <QOrientationReading>
#include <QProcess>
#include "monitorwatcher.h"

class AutoRotateScreen : public QObject
{
    Q_OBJECT
public:
    enum RotateDir{
        Normal = 0,         // 顺时针旋转 0
        Inverted,           // 顺时针旋转 180
        Left,               // 顺时针旋转 270
        Right,              // 顺时针旋转 90
    };
    static AutoRotateScreen* instance(QObject *parent = nullptr);
    void start();
    void stop();

signals:
    void screenRotate(RotateDir dir);

private:
    AutoRotateScreen(QObject *parent = nullptr);
    RotateDir getScreenDirection();
    void init();
    void setScreenDirection(const RotateDir dir);

private slots:
    void onReadingChanged();
    void onActiveChanged();

private:
    QOrientationSensor       *m_pSensor;
    RotateDir                m_curScreenDirection;  // 当前屏幕的旋转方向
    MonitorWatcher           *monitorWatcher = nullptr;
};

#endif // AUTOROTATESCREEN_H
